#include <my_head.h>
int main(int argc, char const *argv[])
{
     FILE *fp = NULL;
    if(NULL == (fp = fopen("time.txt","a+"))){
        printf("文件打开失败\n");
        exit(-1);
    }
    printf("文件打开成功\n");
    int count = 1;
    int line = 1;
    int value = 0;
    while(EOF != (value = fgetc(fp))){
        if('\n' == value){
            line++;
        }
    }
    time_t sec = 0;
    struct tm *p = NULL;
    count = line;
while (1){ 
    if(-1 == time(&sec))
    ERR_LOG("time error");
    if(NULL == (p = localtime(&sec)))
        ERR_LOG("localtime error");
    fprintf(fp,"%d.%04d-%02d-%02d %02d:%02d:%02d\n",\
            count++, p->tm_year + 1900,p->tm_mon +1,p->tm_mday,\
            p->tm_hour,p->tm_min,p->tm_sec);
            
    fflush(fp);
    printf("%d.%04d-%02d-%02d %02d:%02d:%02d\n",\
            count - 1,p->tm_year + 1900, p->tm_mon + 1, p->tm_mday, \
            p->tm_hour, p->tm_min, p->tm_sec);
        sleep(1);
    }
    fclose(fp);
    return 0;
}

